package com.baidu.echarts;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRawValue;

import java.util.ArrayList;
import java.util.List;

/**
 * Jackson的注解请参照下面的url
 * https://www.jianshu.com/p/a0741842d9da
 */
public class Option {

    @JsonProperty(index = 1)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Title title;
    @JsonProperty(index = 2)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Tooltip tooltip;
    @JsonProperty(index = 3)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Legend legend;
    @JsonProperty(index = 4)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Toolbox toolbox;
    @JsonProperty(index = 5)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Boolean calculable;

    @JsonProperty(index = 10)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<XYAxis> xAxis;
    @JsonProperty(index = 11)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<XYAxis> yAxis;
    @JsonProperty(index = 50)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<Series> series;

    @JsonRawValue
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String customAttribute;

    public List<XYAxis> getxAxis() {
        return xAxis;
    }

    public void setxAxis(List<XYAxis> xAxis) {
        this.xAxis = xAxis;
    }

    public List<XYAxis> getyAxis() {
        return yAxis;
    }

    public void setyAxis(List<XYAxis> yAxis) {
        this.yAxis = yAxis;
    }

    public Title getTitle() {
        return title;
    }

    public Title setTitle(Title title) {
        this.title = title;
        return this.title;
    }

    /**
     *
     * 创建一个新的Title实例，注意：每次调用都会初始化Title对象
     * <br><br>
     *     <b>示例代码：</b><br>
     *     option.buildTitle()<br>
     *              .setText("你好") <br>
     *              .setSubtext("hello")<br>
     *              .setX("300");<br>
     * @return
     */
    public Title buildTitle() {
        this.title = new Title();
        return this.title;
    }

    public Tooltip getTooltip() {
        return tooltip;
    }

    public void setTooltip(Tooltip tooltip) {
        this.tooltip = tooltip;
    }

    /**
     * 创建一个新的Tooltip实例，注意：每次调用都会初始化Tooltip对象
     * <br><br>
     *     <b>示例代码①：</b><br>
     *        option.buildTooltip()<br>
     *                 .setTrigger("trigger")<br>
     *                 .setFormatter("formater")<br>
     *                 .buildAxisPointer()   // 可以在设置Tooltip的同时，创建AxisPointer<br>
     *                     .setType("stype");<br><br>
     *      <b>示例代码②：</b><br>
     *          也可以使用下面的方式实例化AxisPointer和它的LineStyle<br>
     *        option.getTooltip().getAxisPointer().buildLineStyle()<br>
     *                 .setType("type")<br>
     *                 .setWidth(250);<br>
     * @return
     */
    public Tooltip buildTooltip() {
        this.tooltip = new Tooltip();
        return this.tooltip;
    }

    public Legend getLegend() {
        return legend;
    }

    public Option setLegend(Legend legend) {
        this.legend = legend;
        return this;
    }

    /**
     * 创建一个新的Legend实例，注意：每次调用都会初始化Legend对象
     * <br><br>
     * <b>示例代码：</b><br>
     *         option.buildLegend()<br>
     *                 .setOrient("orient")<br>
     *                 .setX("x")<br>
     *                 .setData(Arrays.asList(new String[]{"1","2","3"}));<br>
     *
     * @return
     */
    public Legend buildLegend() {
        this.legend = new Legend();
        return this.legend;
    }

    public Boolean getCalculable() {
        return calculable;
    }

    public void setCalculable(Boolean calculable) {
        this.calculable = calculable;
    }


    public Toolbox getToolbox() {
        return toolbox;
    }

    public void setToolbox(Toolbox toolbox) {
        this.toolbox = toolbox;
    }


    /**
     * 创建一个新的Toolbox实例，注意：每次调用都会初始化Toolbox对象
     * <br><br>
     *      <b>示例代码：</b><br>
     *             option.buildToolbox()<br>
     *                 .setShow(true)<br>
     *                 .buildFeature()  // 可以同时设置Feature的属性，但是必须得先调用此build方法<br>
     *                     .setRestore(new MarkItem(true))<br>
     *                     .setMark(new MarkItem(true))<br>
     *                     .setSaveAsImag(new MarkItem(true));<br><br>
     *
     *      请使用以下代码完成DataView和MagicType的设置<br>
     *              option.getToolbox().getFeature()<br>
     *                 .buildDataView()<br>
     *                 .setShow(true)<br>
     *                 .setReadOnly(true);<br><br>
     *
     *         option.getToolbox().getFeature()<br>
     *                 .buildMagicType()<br>
     *                 .setShow(true)<br>
     *                 .setType(Arrays.asList(new String[]{"A","B","C"}));<br>
     * @return
     */
    public Toolbox buildToolbox() {
        this.toolbox = new Toolbox();
        return this.toolbox;
    }

    public List<Series> getSeries() {
        return series;
    }

    public void setSeries(List<Series> series) {
        this.series = series;
    }

    /**
     * 由于Series中数据属性多，所以，使用init初始化一个Series列表后，需要使用后续的代码完成初始化
     * <br><br>
     *      <b>示例代码：</b><br>
     *  // 使用以下示例代码模拟获取数据的过程<br>
     *  List<SeriesData>seriesDataList = new ArrayList<>();<br>
     *         for (int i=0;i< 4;i++){<br>
     *             seriesDataList.add(new SeriesData("name"+i,"value"+i));<br>
     *         }<br><br>
     *  // 使用以下示例代码完成其中一个Series的添加<br>
     *    option.getSeries().add(<br>
     *            Series.build().setName("name")<br>
     *                    .setType("type")<br>
     *                    .setRadius("radius")<br>
     *                    .setStack("stack")<br>
     *                    .setCenter(Arrays.asList(new String[]{"Q", "W", "E"}))<br>
     *                    .setData(seriesDataList)<br>
     *         );<br>
     */
    public void initSeries() {
        this.series = new ArrayList<>();
    }


    public String getCustomAttribute() {
        return customAttribute;
    }

    public void setCustomAttribute(String customAttribute) {
        this.customAttribute = customAttribute;
    }
}
